package UIFree.slideshow
{
	import UIFree.effects.uif_effect;
	import UIFree.uif_component;
	import UIFree.uif_ecomponent;
	
	import flash.display.DisplayObject;
	import flash.geom.Rectangle;

	public class ss_slideFade extends uif_ecomponent {
		protected var _inSlide	: uif_ecomponent;
		protected var _outSlide	: uif_ecomponent;
		protected var _outLayer	: uif_ecomponent;
		private var _mask		: uif_ecomponent;
		private var _effect		: uif_effect;
		
		
		public function ss_slideFade(parent:uif_component, effectClass: Class, 
					ax:int=0, ay:int=0, awidth:int=0, aheight:int=0, styleClass:String='') {
			super(parent, ax, ay, awidth, aheight, styleClass);
			var inner: Rectangle = getInner();
			_mask		= new uif_ecomponent(this, inner.x, inner.y, inner.width, inner.height, 'white');
			_inSlide 	= new uif_ecomponent(this, inner.x, inner.y, inner.width, inner.height); 
			_outSlide 	= new uif_ecomponent(this, inner.x, inner.y, inner.width, inner.height);
			_outLayer	= new uif_ecomponent(_outSlide, inner.x, inner.y, inner.width, inner.height);
			setEffect(effectClass);
			
			_inSlide.mask	= _mask;
			_outSlide.mask	= _mask;
			
			applyChildsStyle();
//			_effect.mask	= _mask;
		}
		
		public function get effect(): uif_effect {
			return _effect;
		}
		
		public function setEffect(effectClass: Class): void {
			if (_outSlide.numChildren > 1) 
				(_outSlide.getChildAt(1) as uif_effect).dispose();
			_effect	= new effectClass(_outSlide);
		}
		
		public function get inObject(): DisplayObject {
			return (_inSlide.numChildren > 0)?_inSlide.getChildAt(0):null;
		}
		
		public function set inObject(a_object: DisplayObject): void {
			if (_inSlide.numChildren > 0) _inSlide.removeChilds();
			if (a_object) _inSlide.addChild(a_object);
		}
		
		public function get outObject(): DisplayObject {
			return (_outLayer && (_outLayer.numChildren > 0))?_outLayer.getChildAt(0):null;
		}
		
		public function set outObject(a_object: DisplayObject): void {
			if (_outLayer.numChildren > 0) _outLayer.removeChilds();
			if (a_object) _outLayer.addChild(a_object);
		}
		
		public function get outLayer(): uif_ecomponent {
			return _outLayer;
		}
		
		public function assignSource(a_slide: DisplayObject, startParams: Object = null): void {
			var outSlide: DisplayObject = _outLayer.getChildAt(0);
			if (outSlide) {
				inObject 	= outObject;
				outObject 	= a_slide;
			} else {
				if (!inObject)inObject = a_slide;
				else outObject = a_slide;
			}
			
			if (startParams) start(startParams);
		}
		
		protected function doBeforeStart(): void {
		}
		
		protected function doStart(effectParams: Object): void {
			effect.start(effectParams);
		} 
		
		public function start(effectParams: Object): void {
			if (inObject && outObject) {
				doBeforeStart();
				doStart(effectParams);
			}
		}
	}
}